    let f = 1;
    let phone_bool = false;
    let pass_bool = false;
    let mail_bool = false;
    let name_bool = false;

    $("#mail_re").hide();
    $("#register_type").click(function () {
        if (f === 1) {
            $("#phone_re").show();
            $("#mail_re").hide();
            $("#register_type").text("使用邮箱注册");
            f = 2;
        } else if (f === 2) {
            $("#phone_re").hide();
            $("#mail_re").show();
            f = 1;
            $("#register_type").text("使用手机号注册");
        }
    });

    function isPhoneNo(phone) {
        const pattern = /^1[345789]\d{9}$/;
        return pattern.test(phone);
    }

    $("#phone").blur(function () {
        let pn = $("#phone").val();
        if (isPhoneNo(pn)) {
            $("#phone_v").text("");
            $.ajax({
                async: true,
                type: "GET",
                data: {"uPhone": pn},
                url: "/user/phoneCheck",
                success: function (data) {
                    if (data !== "1") {
                        $("#phone_v").css("color", "red").text("该手机号已注册");
                    } else {
                        phone_bool = true;
                    }
                }
            });
        } else {
            $("#phone_v").css("color", "red").text("请输入正确的手机号");
        }
    });


    function isEmail(email) {
        var reg = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        return reg.test(email);
    }

    $("#email").blur(function () {
        const e = $("#email").val();
        if (e != null || e.length > 0) {
            let b = isEmail(e);
            if (b) {
                $("#mail_v").text("");
                $.ajax({
                    async: true,
                    type: "GET",
                    data: {"uEmail": e},
                    url: "/user/checkEmail",
                    success: function (data) {
                        if (data == "1") {
                            $("#mail_v").text("");
                            mail_bool = true;
                        } else {
                            $("#mail_v").css("color", "red").text("该邮箱已注册");
                            mail_bool = false;
                        }
                    }
                });
            } else {
                $("#mail_v").css("color", "red").text("请输入正确的邮箱");
                mail_bool = false;
            }
        }
    });

    $("#user_name").blur(function () {
        let name = $("#user_name").val();
        if (name != null) {
            $.ajax({
                async: true,
                type: "GET",
                data: {"uName": name},
                url: "/user/checkName",
                success: function (data) {
                    if (data == "1") {
                        $("#name_v").text("");
                        name_bool = true;
                    } else {
                        console.log(data);
                        $("#name_v").css("color", "red").text("该用户名已存在");
                        name_bool = false;
                    }
                }
            });
        } else {
            mail_bool = false;
        }
    });

    $("#pass2").blur(function () {
        let p1 = $("#pass1").val();
        let p2 = $("#pass2").val();
        if (p1.length !== p2.length) {
            $("#pass_v").css("color", "red").text("密码不一致");
            pass_bool = false;
        } else {
            if (p1 === p2) {
                $("#pass_v").text("");
                pass_bool = true;
            } else {
                pass_bool = false;
            }
        }
    });





function doRegister(){
    if ((mail_bool && pass_bool && name_bool) || (phone_bool && pass_bool && name_bool)) {
        let phone = $("#phone").val();
        let email = $("#email").val();
        let name = $("#user_name").val();
        let pass = $("#pass1").val();
        let sex = $('input[name="sex"]:checked').val();
        $.ajax({
            type: "POST",
            data: {"uPhone": phone, "uPass": pass, "uEmail": email, "uName": name, "uSex": sex},
            url: "/user/doRegister",
            success:function (data) {
                console.log(data);
            }
            /*success: function (data) {
                console.log(data);
                if (data.code === 200) {
                    window.location.href='/login/index'
                } else {
                    alert(data.msg);
                }
            },
            error:function (){
                alert("网络出错，请重试");
            }*/
        });
    }

}